package hu.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import hu.mapper.UserMapper;
import hu.pojo.PageBean;
import hu.pojo.User;
import hu.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

//Service层的实现类，写具体方法，设置默认值，连接Dao层
@Service//标记业务层
public class UserServiceImpl implements UserService { //实现类继承Service

    @Autowired//注入Dao层的接口
    private UserMapper userMapper;
    //登录
    @Override//表明这为重写的方法
    public User login(User user) {
        return userMapper.getByAccountAndPassword(user);
    }

    //更新工资
    @Override
    public void update(User user) {
        user.setUpdateTime(LocalDateTime.now()); //设置更改时间
        userMapper.update(user);
    }

    //显示(查询员工信息)
    @Override
    public PageBean page(Integer page, Integer pageSize, String username, Integer moneyBegin, Integer moneyEnd) {

        //设置分页参数
        PageHelper.startPage(page,pageSize);

        //执行查询
         List<User> userList = userMapper.page(username,moneyBegin,moneyEnd);

         //获取分页结果
        Page<User> p = (Page<User>) userList;

        //封装PageBean对象
         PageBean pageBean= new PageBean(p.getTotal(),p.getResult());

         return pageBean;
    }
}
